package com.wy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wy.entity.UserInfo;
import com.wy.mapper.GoodsEvaluationMapper;
import com.wy.mapper.UserInfoMapper;
import com.wy.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * @Author:王渝
 * @Date: 2022/11/30  11:20
 * @Version 1.0
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private GoodsEvaluationMapper goodsEvaluationMapper;

    @Override
    public Boolean register(UserInfo userInfo) {
        //密码md加密
        userInfo.setPassword(DigestUtils.md5DigestAsHex(userInfo.getPassword().getBytes()));
        int insert = userInfoMapper.insert(userInfo);
        //保存用户信息
        if(insert > 0){
            return true;
        }
        return false;
    }

    @Override
    public int updateBalanceTime() {
        return userInfoMapper.updateBalanceTime();
    }

    @Override
    public String queryEmailByOrderId(Long orderId) {
        return userInfoMapper.queryEmailByOrderId(orderId);
    }

    @Override
    public UserInfo queryUserInfoByGoodsId(Long goodsId) {
        return userInfoMapper.queryUserInfoByGoodsId(goodsId);
    }

    @Override
    public UserInfo queryUserInfoByUserId(Long userId) {
        return userInfoMapper.queryUserInfoByUserId(userId);
    }

}
